using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using ApiTest.Api.Entity;
using System.Linq;
using ApiTest.Api.Db;
using ApiTest.Api.Repository;
using ApiTest.Api.Params;
using Microsoft.Extensions.Configuration;
using ApiTest.Api.Utils;
using Microsoft.AspNetCore.Authorization;
using Admin3000.Backend.Api.Params;

namespace ApiTest.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class CommentController : ControllerBase
    {
        private IConfiguration _configuration;
        private IRepository<Comment> _commentRepository;
        private TokenParameter _tokenParameter;

        public  CommentController(IConfiguration configuration, IRepository<Comment> commentRepository)
        {
            _configuration = configuration;
          _commentRepository = commentRepository;
            _tokenParameter = _configuration.GetSection("TokenParameter").Get<TokenParameter>();
        }

        [HttpGet]
        public dynamic Get()
        {
            var Comment=_commentRepository.Table.ToList();

            return new{
                Code=1000,
                Data=Comment,
                Msg="查询评论表成功"
            };
        }
        [HttpPost]
        public dynamic Post(CreateComment newComment)
        {
            var Comment=new Comment{
                SpuId= newComment.SpuId,
                UserId= newComment.UserId,
                Content=newComment.Content
            };
            _commentRepository.Insert(Comment);

            return new {
                Code=1000,
                Data=Comment,
                Msg="添加评论成功"
            };
        }
        



        
        
        

        
       
    }
}